using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

//using Indeco.G24.Web;
//using Indeco.G24.Data;
using Indeco.G24.Services;
using Indeco.G24.Entities;
//using Indeco.G24.Web.UI;

namespace Indeco.G24.Website.UserControls
{
    public partial class Login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                NguoiDungService nguoiDungService = new NguoiDungService();
                TList<NguoiDung> nguoiDung = nguoiDungService.Find("TenSuDung = '" + Membership.GetUser().UserName + "'");
                Session["IDNguoiDung"] = nguoiDung[0].IDNguoiDung;
                NguoiDungNhaCungCapService nguoiDungNhaCungCapService = new NguoiDungNhaCungCapService();
                TList<NguoiDungNhaCungCap> listNN = nguoiDungNhaCungCapService.GetByIDNguoiDung(new Guid(Session["IDNguoiDung"].ToString()));
                Session["IDNhaCungCap"] = listNN[0].IDNhaCungCap;
                if (Session["IDNhaCungCap"].ToString() != Guid.Empty.ToString())
                {
                    HyperLink link = (HyperLink)loginView.FindControl("linkControlPanel");
                    link.Visible = true;
                }
            }
            catch
            { }
        }

        protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
        {
            Session["IDNhaCungCap"] = Guid.Empty;
            Session["IDNguoiDung"] = Guid.Empty;
            Session["TenSuDung"] = "";
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            try
            {
                NguoiDungService nguoiDungService = new NguoiDungService();
                TList<NguoiDung> nguoiDung = nguoiDungService.Find("TenSuDung = '" + Membership.GetUser().UserName + "'");
                Session["IDNguoiDung"] = nguoiDung[0].IDNguoiDung;
                NguoiDungNhaCungCapService nguoiDungNhaCungCapService = new NguoiDungNhaCungCapService();
                TList<NguoiDungNhaCungCap> listNN = nguoiDungNhaCungCapService.GetByIDNguoiDung(new Guid(Session["IDNguoiDung"].ToString()));
                Session["IDNhaCungCap"] = listNN[0].IDNhaCungCap;
            }
            catch
            { }
        }

    }
}